package com.interpreter;

import com.interpreter.iface.Expression;
import com.interpreter.iface.extend.AndExpression;
import com.interpreter.iface.extend.OrExpression;
import com.interpreter.iface.impl.TerminalExpression;

/*
    得到一个明确的结果：
        可以 or 不可以
        对 or 不对
 */
public class Test {
    public static void main(String[] args) {
        String poem_verse = "人生得意须尽欢，莫使金樽空对月。俱怀逸兴壮思飞，欲上青天揽明月";

        System.out.print("有\"月\"字：" + getExpressionMonotonous().interpret(poem_verse) + "\n");

        System.out.print("同时满足有\"月\"、\"上青天\"和\"金樽\"全部：" + getExpressionAnd().interpret(poem_verse) + "\n");

        System.out.print("只要满足有\"人生\"、\"九万里\"和\"扶摇\"其一：" + getExpressionOr().interpret(poem_verse) + "\n");

    }

    /*
        仅判断一个条件
     */
    public static Expression getExpressionMonotonous() {
        return new TerminalExpression("月");
    }

    /*
        需同时满足多个条件
     */
    public static Expression getExpressionAnd() {
        Expression exp1 = new TerminalExpression("月");
        Expression exp2 = new TerminalExpression("上青天");
        Expression exp3 = new TerminalExpression("金樽");
        return new AndExpression(exp1, exp2, exp3);
    }

    /*
        满足其中一个条件即可
     */
    public static Expression getExpressionOr() {
        Expression exp1 = new TerminalExpression("人生");
        Expression exp2 = new TerminalExpression("九万里");
        Expression exp3 = new TerminalExpression("扶摇");
        return new OrExpression(exp1, exp2, exp3);
    }
}
